package de.tabuma.wsdl2xform.xform.view;

import de.tabuma.lib.tabumaview;
import de.tabuma.wsdl2xform.xform.*;
import de.tabuma.wsdl2xform.xform.controller.*;
import de.tabuma.wsdl2xform.xform.entity.*;
import de.tabuma.wsdl2xform.xform.logik.*;
import de.tabuma.wsdl2xform.xform.view.*;

import java.io.*;
import java.util.*;
import java.util.logging.*;
import javax.servlet.*;
import javax.servlet.http.*;

/**
 * @author $Author: alefen $
 * @version $Revision: 1.1 $
 * @since $Date: 2009/12/30 01:10:56 $
 */

public class projectPage3 extends tabumaview {

    private static final Logger log = Logger.getLogger(projectPage3.class.getName());

    public projectPage3(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
        try {

            String url = de.tabuma.wsdl2xform.controller.constants.SERVLET_NAME;
            url += "?";
            url += de.tabuma.wsdl2xform.controller.constants.MAINNAV+"="+de.tabuma.wsdl2xform.controller.constants.NAVID_CREATEXFORM;
            url += "&amp;";
            url += constants.XFORM_NAV+"="+constants.NAV_SHOW_PROJECT;
            url += "&amp;";
            url += constants.PROJECT_ID+"="+request.getAttribute(constants.PROJECT_ID);

            log.fine("url:"+url);

            int projectInt = 0;
            if(request.getAttribute(constants.SHOW_PROJECT_MODE)!=null) {
                projectInt = Integer.valueOf((String) request.getAttribute(constants.SHOW_PROJECT_MODE)).intValue();
            }

            long key = 0;
            if(request.getParameter(constants.T_DEFINITIONS_KEY)!=null) {
                key = Long.valueOf(request.getParameter(constants.T_DEFINITIONS_KEY));
            }

            log.fine("projectInt:"+projectInt);

            Project project = (Project) request.getAttribute(constants.PROJECT);

            log.fine("project:"+project);

            log.fine("Showing content head");

            out.println("\t<div class=\"tab\">");
            out.println("\t\t<div class=\"tabelementbeginnclose\"></div>");
            switch(projectInt) {
                case constants.SHOW_PROJECT_MODE_NULL:
                    out.println("\t\t<div class=\"tabelementopen\">"+constants.getValue("projectinformation")+"</div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_XFORM+"\">"+constants.getValue("xform")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_HTML+"\">"+constants.getValue("html")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_WSDL+"\">"+constants.getValue("wsdl")+"</a></div>");
                    break;
                case constants.SHOW_PROJECT_MODE_XFORM:
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_NULL+"\">"+constants.getValue("projectinformation")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementopen\">"+constants.getValue("xform")+"</div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_HTML+"\">"+constants.getValue("html")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_WSDL+"\">"+constants.getValue("wsdl")+"</a></div>");
                    break;
                case constants.SHOW_PROJECT_MODE_HTML:
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_NULL+"\">"+constants.getValue("projectinformation")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_XFORM+"\">"+constants.getValue("xform")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementopen\">"+constants.getValue("html")+"</div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_WSDL+"\">"+constants.getValue("wsdl")+"</a></div>");
                    break;
                case constants.SHOW_PROJECT_MODE_WSDL:
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_NULL+"\">"+constants.getValue("projectinformation")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_XFORM+"\">"+constants.getValue("xform")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementclose\"><a href=\""+url+"&amp;"+constants.SHOW_PROJECT_MODE+"="+constants.SHOW_PROJECT_MODE_HTML+"\">"+constants.getValue("html")+"</a></div>");
                    out.println("\t\t<div class=\"tabelementopen\">"+constants.getValue("wsdl")+"</div>");
                    break;
            }
            out.println("\t\t<div class=\"tabelementclose\"></div>");
            out.println("\t</div>");

            log.fine("Showing content");

            out.println("<div class=\"contentContent\">");
            switch(projectInt) {
                case constants.SHOW_PROJECT_MODE_NULL:
                    out.println("<div class=\"cols\">");

                    out.println("\t<div class=\"col1\">");
                    out.println("\t\t<div class=\"col1_head\">"+constants.getValue("name")+"</div>");
                    out.println("\t\t<div class=\"col1_content\">"+project.getName()+"</div>");
                    out.println("\t</div>");

                    out.println("\t<div class=\"col2\"></div>");

                    out.println("\t<div class=\"col1\">");
                    out.println("\t\t<div class=\"col1_head\">"+constants.getValue("url")+"</div>");
                    out.println("\t\t<div class=\"col1_content\">"+project.getUrl()+"</div>");
                    out.println("\t</div>");

                    out.println("\t<div class=\"col2\"></div>");

                    out.println("\t<div class=\"col1\">");
                    out.println("\t\t<div class=\"col1_head\">"+constants.getValue("method")+"</div>");
                    out.println("\t\t<div class=\"col1_content\">"+project.getMethod()+"</div>");
                    out.println("\t</div>");

                    out.println("\t<div class=\"col2\"></div>");

                    out.println("\t<div class=\"col1\">");
                    out.println("\t\t<div class=\"col1_head\">"+constants.getValue("description")+"</div>");
                    out.println("\t\t<div class=\"col1_content\">"+project.getDescription()+"</div>");
                    out.println("\t</div>");

                    out.println("\t<div class=\"col2\"></div>");

                    out.println("</div>");

                    break;
                case constants.SHOW_PROJECT_MODE_XFORM:
                    out.println("<iframe src=\"wsdl2xform?"+constants.PROJECT_ID+"="+project.getId()+"\" class=\"iframe\">");
                    out.println("</iframe>");
                    break;
                case constants.SHOW_PROJECT_MODE_HTML:
                    out.println("<iframe src=\"wsdl2html\" class=\"iframe\">");
                    out.println("</iframe>");
                    break;
                case constants.SHOW_PROJECT_MODE_WSDL:
                    out.println("<iframe src=\"wsdlfile?"+constants.PROJECT_ID+"="+project.getId()+"\" class=\"iframe\">");
                    out.println("</iframe>");
                    break;
            }
            out.println("</div>");
        }
        catch(Exception e) {
            log.warning(e.getMessage());
        }
    }
}